package com.scott.ch24.configuration;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 黄后林
 * @version 1.0
 * @date 2021-11-25 09:34:18
 */

@Configuration
@EnableWebMvc
@ComponentScan(value = "com.scott.ch24",useDefaultFilters = false, includeFilters = {
        @ComponentScan.Filter(type = FilterType.ANNOTATION,classes = {Controller.class})
})
public class SpringMVCConfiguration implements WebMvcConfigurer {



    public void addCorsMappings(CorsRegistry registry){

        registry.addMapping("/**")                         //路径
                .allowedOrigins("*")                                 //域名
                .allowedMethods("GET", "POST")                       //方法
                .allowedHeaders("*")                                 //请求投
                .allowCredentials(true)                              //证书
                .maxAge(3600*24);                                    //时间
    }

}
